package com.py.framework.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.py.framework.common.controller.SystemController;
import com.py.framework.core.common.Page;
import com.py.framework.core.rest.support.RestServiceResult;
import com.py.framework.entity.WorkFlowWrapper;
import com.py.framework.service.ActHistoryService;

/**
 * 流程历史Controller
 * @author Leegern
 * @date   2018年5月23日
 */
@RestController
@RequestMapping("/act")
public class ActHistoryController extends SystemController {
	
	@Autowired
	private ActHistoryService actHistoryService;
	
	/**
	 * @api {post} /act/queryActHistoryDataList.json 分页查询历史流程列表
	 * @apiName queryActHistoryDataList
	 * @apiVersion 0.0.1
	 * @apiGroup 流程历史
	 * @apiParam {HttpServletRequest} request 请求实例
	 * @apiParam {int} page  当前页码
	 * @apiParam {int} limit 每页条数
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} taskId 任务Id
	 * @apiSuccess {String} busName 业务名称
	 * @apiSuccess {String} processDefinitionName 流程名称
	 * @apiSuccess {String} taskName 任务名称
	 * @apiSuccess {String} taskStartTime 开始时间
	 * @apiSuccess {String} taskEndTime 结束时间
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":2,"data":[{"taskId":"100","busName":"审批","processDefinitionName":"请假","taskName":"信用中心","taskStartTime":"2018-04-27 14:33:00","taskEndTime":"2018-04-27 14:33:37"}]}
	 */
	@RequestMapping(value = "/queryActHistoryDataList", method = RequestMethod.POST)
	public RestServiceResult<List<WorkFlowWrapper>> queryActHistoryDataList(HttpServletRequest request, int page, int limit, String startTime, String endTime, String processName) {
		Page pager = super.getPage(page, limit);
		long userId = super.pickUserId(request);
		List<WorkFlowWrapper> datas = actHistoryService.queryActHistoryDataList(pager, userId, startTime, endTime, processName);
		return super.getPageSuccessRestServiceResult(pager.getTotalCount(), datas);
	}
}